import React from 'react';
import {useSelector,useDispatch} from "react-redux";
import { useHistory } from 'react-router';

const Login = () => {
    const dispatch=useDispatch();
    const history=useHistory();
    const islogin=useSelector(state=>state.islogin);
    const login=()=>{
        fetch("http://39.96.84.223:4567/verify/adminlogin",{
            method:'post',
            body:JSON.stringify({username:'fdy121',passwd:'1234567'}),
        })
        .then(res=>res.json())
        .then(res=>{
            console.log(res);
            dispatch({type:'LoginSucess',islogin:true})
            history.replace('/')
        })
        .catch((err)=>{
            alert('用户名或密码不对');
        })
    }
    return (
        <div>
            <button onClick={login}>登录</button>
        </div>
    )
}

export default Login
